package com.tangyuan.user.feign;

import com.tangyuan.common.result.ResultCodeEnum;
import com.tangyuan.dto.GivingLiveGiftDto;
import com.tangyuan.common.result.Result;
import com.tangyuan.feignapis.user.IUserBalanceFeignClient;
import com.tangyuan.model.UserBalance;
import com.tangyuan.user.service.IUserBalanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class UserBalanceClient implements IUserBalanceFeignClient {

    @Autowired
    private IUserBalanceService userBalanceService;

    @GetMapping("/feignApi/user/getUserBalance")
    @Override
    public UserBalance getUserBalance(@RequestParam(value = "userId") Long userId) {
        return userBalanceService.getUserBalance(userId);
    }

    @PostMapping("/feignApi/user/saveUserBalance")
    @Override
    public void saveUserBalance(@RequestBody UserBalance userBalance) {
        userBalanceService.save(userBalance);
    }

    @PostMapping("/feignApi/user/verifyParameter")
    @Override
    public Result<ResultCodeEnum> verifyParameter(@RequestBody GivingLiveGiftDto givingLiveGiftDto) {
        return userBalanceService.verifyParameter(givingLiveGiftDto);
    }

    @PostMapping("/feignApi/user/giveLiveGiftUpdateBalance")
    @Override
    public Result<Map<String, UserBalance>> giveLiveGiftUpdateBalance(@RequestBody GivingLiveGiftDto givingLiveGiftDto) {
        return userBalanceService.giveLiveGiftUpdateBalance(givingLiveGiftDto);
    }

    @PostMapping("/feignApi/user/refundLiveGiftUpdateBalance")
    @Override
    public Result<ResultCodeEnum> refundLiveGiftUpdateBalance(@RequestBody GivingLiveGiftDto givingLiveGiftDto) {
        return userBalanceService.refundLiveGiftUpdateBalance(givingLiveGiftDto);
    }
}
